//
//  View3Controller.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/3/8.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class View3Controller: UIViewController,UITableViewDelegate,UITableViewDataSource{

    override func viewDidLoad() {
        super.viewDidLoad()
        let tableView = UITableView(frame: CGRect(x: 0, y: 65, width: self.view.bounds.width, height: self.view.bounds.height - 115))
        tableView.delegate = self
        tableView.dataSource = self
        self.view.addSubview(tableView)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
// MARK: -UITableViewDataSource
extension View3Controller{
    // MARK: -设置每个Section显示多少条数据
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 8;
    }
    
    // MARK: -设置每行数据
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellId")
        if(cell == nil){
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cellId")
        }
        cell?.textLabel?.text = "爱秀\(indexPath.row)"
        cell?.detailTextLabel?.text = "爱秀多一点"
        
        cell?.imageView?.image = UIImage(named: "\(indexPath.row % 6)")
        cell?.accessoryType = .disclosureIndicator
        return cell!
    }
    // MARK: -行点击事件
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.navigationController?.pushViewController(TestController(), animated: true)
    }
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        var title = "";
        if section != 0 {
            title = " "
        }
        return title
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
}
